import java.util.ArrayDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class bockequeue {
    int maxsize;
    ReentrantLock re=new ReentrantLock();
    Condition c1=re.newCondition();
    Condition c2=re.newCondition();
    ArrayDeque<Runnable> array;

    bockequeue(int size){
        maxsize=size;
        array=new ArrayDeque<>(size);
    }

    Runnable poll(TimeUnit timeUnit,Long time){
        re.lock();
        Long t1=System.currentTimeMillis();
        Long t2=0L;
        try{

            while (array.isEmpty()){
                if(t2>=time)return  null;
                else c1.await(time-t2,TimeUnit.MILLISECONDS);
                t2=System.currentTimeMillis()-t1;
            }
            c2.signal();
            return array.poll();

        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            re.unlock();
        }
        return null;
    }

}

 class m extends bockequeue{
     m(int size) {
         super(size);
     }

     @Override
     Runnable poll(TimeUnit timeUnit, Long time) {
         return super.poll(timeUnit, time);
     }
 }
